package com.o2o.app.userCenter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.o2o.app.R;

public class UserInfoItemActivity extends Activity {
	// 跳转姓名
	private static int FORUSERITEMNAME = 5555;
	// 跳转昵称
	private static int FORUSERITEMNICK = 5556;
	// 个性签名
	private static int FORUSERITEMDIY = 5557;
	// 性别
	private static int FORUSERITEMSEX = 5558;
	// 电话
	private static final int FORUSERITEMPHONE = 5559;

	/**
	 * title标签
	 */
	private TextView tv_title;

	/**
	 * 是否保密
	 */
	private CheckBox parking_info;

	/**
	 * 保存按钮
	 */
	private Button btn_pass;

	/**
	 * 名字编辑按钮
	 */
	private EditText et_name;

	/**
	 * 返回按钮
	 */
	private Button btn_back;

	/**
	 * 隐藏布局
	 */
	private RelativeLayout rlt_bottom;

	/**
	 * 添加手机号
	 */
	private Button btn_register;

	/**
	 * 更换手机号
	 */
	private Button btn_denglu;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_info_item);

		initViews();
		initData();
	}

	private void initViews() {
		tv_title = (TextView) findViewById(R.id.tv_title);

		parking_info = (CheckBox) findViewById(R.id.parking_info);

		et_name = (EditText) findViewById(R.id.et_name);

		rlt_bottom = (RelativeLayout) findViewById(R.id.rlt_bottom);

		btn_back = (Button) findViewById(R.id.btn_back);
		btn_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		btn_pass = (Button) findViewById(R.id.btn_pass);
		btn_pass.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				goneJianPan();
				Intent intent = new Intent();
				intent.putExtra("secrecy", parking_info.isChecked());

				if ("名字".equals(getIntent().getStringExtra("title"))) {

					intent.putExtra("realname", et_name.getText().toString()
							.trim());
					setResult(FORUSERITEMNAME, intent);
				} else if ("昵称".equals(getIntent().getStringExtra("title"))) {

					intent.putExtra("nickname", et_name.getText().toString()
							.trim());
					setResult(FORUSERITEMNICK, intent);
				} else if ("个性签名".equals(getIntent().getStringExtra("title"))) {

					intent.putExtra("diyinfo", et_name.getText().toString()
							.trim());
					setResult(FORUSERITEMDIY, intent);
				} else if ("性别".equals(getIntent().getStringExtra("title"))) {

					intent.putExtra("sex", et_name.getText().toString().trim());
					setResult(FORUSERITEMSEX, intent);
				}

				finish();
			}
		});

		btn_register = (Button) findViewById(R.id.btn_register);
		btn_register.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(UserInfoItemActivity.this,
						MinePhoneManageActivity.class);

				startActivity(intent);
			}
		});

		btn_denglu = (Button) findViewById(R.id.btn_denglu);
		btn_denglu.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(UserInfoItemActivity.this,
						MinePhoneManageActivity.class);

				startActivity(intent);
			}
		});
	}

	private void initData() {
		tv_title.setText(getIntent().getStringExtra("title"));

		if ("手机管理".equals(getIntent().getStringExtra("title"))) {
			rlt_bottom.setVisibility(View.VISIBLE);
			btn_pass.setVisibility(View.GONE);
		}

		et_name.setText(getIntent().getStringExtra("info"));
	}

	/**
	 * 隐藏键盘
	 */
	private void goneJianPan() {
		InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);
		inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus()
				.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
	}

}
